<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/serverUrl.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">签退</h1>
		</header>
		
		<div class="mui-content">
			<!-- 回复框 -->
			<textarea id="message" rows="5" cols="20" placeholder="请输入使用记录/报修原因"></textarea>
			<button id="baoxiu" type="button" class="mui-btn mui-btn-danger" style="float: left; margin-left: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;报修&nbsp;&nbsp;&nbsp;&nbsp;</button>
			<button id="button" type="button" class="mui-btn" style="float: right; margin-right: 20px;">&nbsp;&nbsp;&nbsp;&nbsp;签退&nbsp;&nbsp;&nbsp;&nbsp;</button>
		</div>
	</body>
	<script type="text/javascript">
		//报修按钮
		document.getElementById("baoxiu").onclick = function(){
			var qiantuiJson = {};
			qiantuiJson.user = JSON.parse( localStorage.getItem("userInformation") );
			qiantuiJson.id = localStorage.getItem("pcID");
			qiantuiJson.str = document.getElementById("message").value;
			var flag = confirm("确定要报修吗？");
			if(flag == true){
				$.ajax({
					//请求方式
					type: 'POST',
					dataType: 'json',
					url: serverUrl + "studentBreakComputer",
					headers: {
						'Content-Type': 'application/json;charset=utf-8'
					},
					data: JSON.stringify(qiantuiJson),
					//请求成功
					success: function(data) {
						if(data == "success"){
							//homepage刷新
							var parentPage = plus.webview.getWebviewById('homePage.html');
							mui.fire(parentPage,'refresh1');
							
							mui.toast("报修成功！");
							localStorage.removeItem("qiandao");
							mui.back();
						} else{
							mui.toast(data);
							mui.back();
						}
					},
					//请求失败，包含具体的错误信息
					error: function(e) {
						mui.toast("遇到了未知错误！");
					}
				});
			} else{
				
			}
		};
		
		
		//签退按钮
		document.getElementById("button").onclick = function(){
			var qiantuiJson = {};
			qiantuiJson.user = JSON.parse( localStorage.getItem("userInformation") );
			qiantuiJson.id = localStorage.getItem("pcID");
			qiantuiJson.str = document.getElementById("message").value;
			$.ajax({
				//请求方式
				type: 'POST',
				dataType: 'json',
				url: serverUrl + "studentSignOutComputer",
				headers: {
					'Content-Type': 'application/json;charset=utf-8'
				},
				data: JSON.stringify(qiantuiJson),
				//请求成功
				success: function(data) {
					if(data == "success"){
						//homepage刷新
						var parentPage = plus.webview.getWebviewById('homePage.html');
						mui.fire(parentPage,'refresh1');
						
						mui.toast("签退成功！")
						localStorage.removeItem("qiandao");
						mui.back();
					}
				},
				//请求失败，包含具体的错误信息
				error: function(e) {
					mui.toast("遇到了未知错误！");
				}
			});
		};
	</script>
</html>
